﻿/*
**营业数据汇总页面类
*/
Chenxin.UI.CollectBusinessDataPage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/CollectBusinessData.ashx',
    createGrid: function() {
        return new Chenxin.UI.ReportGrid({
            actionUrl: '/service/CollectBusinessData.ashx?op=Search',
            id: 'test',
            cellBorder: true,
            renderTo: 'div_jsongrid',
            hasRowNumber: false,
            hasCheckBox: false,
            afterRender: function(data) {
                var _this = this;
            },
            scope: this
        });
    },
    showDetailsList: function(o) {

        var i = o.attr('i');
        if (i == '合计') {
            return;
        }
        var n = o.attr('n');
        var p = o.attr('p');
        var title = '『' + o.attr('d') + '』';
        var tr = o.attr('t').split('_');

        switch (tr[0]) {
            case 'house':
                title += '房源'
                break;
            case 'housetrace':
                title += '房源跟盘'
                break;
            case 'customer':
                title += '客需'
                break;
            case 'customertrace':
                title += '客需跟单'
                break;

        }
        switch (tr[1]) {
            case 'sale':
                title += '买卖';
                break;
            case 'rent':
                title += '租赁';
                break;
            case 'count':
                title += '合计';
                break;
        }
        title += '——详细数据';

        var _gridRend = 'd_' + this.grid.renderTo;

        if (!this.detailsWin) {
            this.detailsWin = new Chenxin.UI.Win({
                title: title,
                id: 'win_' + this.grid.renderTo,
                height: 400,
                width: 700,
                content: '<div id=\"' + _gridRend + '\">',
                createBtn: function() {
                    return [{
                        text: '关闭',
                        handler: this.hide
}]
                    }
                });
            }
            if (!this.detailsGrid) {
                this.detailsGrid = new Chenxin.UI.JsonGrid({
                    actionUrl: this.actionUrl + '?op=getdetailgrid',
                    //actionUrl:'/service/housemgr.ashx?op=gethouselist',
                    hasTitle: false,
                    width: 692,
                    height: 349,
                    renderTo: _gridRend,
                    id: 'detailsgrid',
                    hasCheckBox: false,
                    autoLoad: false,
                    scope: this
                });
            }
            this.detailsWin.setTitle(title);
            this.detailsWin.show();
            var param = this.search.getParamJson();
            param.ParentId = i;
            param.ParentType = n;
            param.FatherId = p;
            param.dtype = o.attr('t');
            this.detailsGrid.reload(param, 0);
        },
        initEvent: function() {
            var jsonGrid = this.grid;
            $('#div_path').find('a').live('click', function() {
                var n = $(this).attr('n');
                var i = $(this).attr('i');
                if (n == jsonGrid.param.ParentType && i == jsonGrid.param.ParentId) {
                    return false;
                }

                if (n != undefined) {
                    jsonGrid.param.ParentType = n;
                } else {
                    if (jsonGrid.param.ParentType != undefined) {
                        delete jsonGrid.param.ParentType;
                    }
                }
                if (i != undefined) {
                    jsonGrid.param.ParentId = i;
                } else {
                    if (jsonGrid.param.ParentId != undefined) {
                        delete jsonGrid.param.ParentId;
                    }
                }
                jsonGrid.reload();
                $(this).nextAll().remove();
                return false;
            });

            var _this = this;
            $('.number').live('click', function(e) {
                _this.showDetailsList($(this));
                return false;
            });

            $('.childname').live('click', function(e) {
                var n = $(this).attr('n');
                var i = $(this).attr('i');
                if (n == '40' || n == '50') {
                    return;
                }
                if (this.innerHTML == '合计') {
                    return;
                }
                _this.grid.param.ParentType = n;
                _this.grid.param.ParentId = i;
                _this.grid.reload();

                //$('#div_path').append('');
                $('#div_path').append('<a href="#" title="' + this.title + '" n=\"' + _this.grid.param.ParentType + '\" i=\"' + _this.grid.param.ParentId + '\"> >>' + this.innerHTML + '</a>');
            });

        },
        createSearch: function() {
            return new Chenxin.UI.CollectBusinessDataSearch({
                scope: this
            });
        }
    });

/*
**查询条件类
*/
Chenxin.UI.CollectBusinessDataSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    actionUrl: 'service/CollectBusinessData.ashx',
    id: "house_search",
    initEvent: function() {
        var objSearch = this;
        /*************事件：查询事件*************/
        $("#btSearch").click(function() {
            if ($("#txtStartDate").val() == "" && $("#txtEndDate").val() == "") {
                alert("请输入日期进行检索");
                $("#txtStartDate").focus();
                return;
            }
            objSearch.refresh();
        });
        /*************事件：今天营业动态*************/
        $("#aSearchYesterday").click(function() {
            $("#txtStartDate").val(objSearch.lsDate.Today);
            $("#txtEndDate").val(objSearch.lsDate.Today);
            objSearch.refresh();
        });
        /*************事件：本周营业动态*************/
        $("#aSearchCurWeek").click(function() {
            $("#txtStartDate").val(objSearch.lsDate.CurStartWeekDay);
            $("#txtEndDate").val(objSearch.lsDate.CurEndWeekDay);
            objSearch.refresh();
        });
        /*************事件：当月营业动态*************/
        $("#aSearchCurMon").click(function() {
            $("#txtStartDate").val(objSearch.lsDate.CurStartMonth);
            $("#txtEndDate").val(objSearch.lsDate.CurEndMonth);
            objSearch.refresh();
        });
    },
    refresh: function() {
        var Json = this.getParamJson();
        this.scope.grid.reload(Json);
        $('#div_path').html('路径：<a href="#">返回顶层</a>');
    },
    initComponent: function() {
        this.superclass.initComponent.call(this);
        var lsDate = eval("(" + $("#ctl00_main_lsDate").val() + ")");
        this.lsDate = lsDate;
    }
});


$(document).ready(function() {
    var objPg = new Chenxin.UI.CollectBusinessDataPage();
});